package com.hrzyit.whistle.cases.presenter

import com.hrzyit.base.data.protocol.ApiPageInfo
import com.hrzyit.base.ext.execute
import com.hrzyit.base.presenter.BasePresenter
import com.hrzyit.base.rx.BaseObserver
import com.hrzyit.whistle.cases.data.bean.AuthMsgEntity
import com.hrzyit.whistle.cases.data.bean.AuthMsgEntityVo
import com.hrzyit.whistle.cases.data.bean.CaseInfoEntity
import com.hrzyit.whistle.cases.presenter.view.CaseListView
import com.hrzyit.whistle.cases.service.ICaseCenterService
import com.hrzyit.whistle.cases.service.ICaseTypeService
import javax.inject.Inject

/**
 * 案件汇总 Presenter
 * @author YangWei
 * @date 2019/3/26
 */
class CaseListPresenter @Inject constructor():BasePresenter<CaseListView>() {

    @Inject
    lateinit var caseTypeService: ICaseTypeService

    @Inject
    lateinit var caseCenterService: ICaseCenterService

    /**
     * 获取指定案件类型数据列表
     * @author YangWei
     * @date 2019/4/8
     * @param caseType  案件数据类型：=0，所有
     * @param pageNo    分页：起始记录数，默认0
     * @param pageSize  分页：每页最大记录数，默认值：@link {CaseConstant.PAGE_SIZE}
     * @return 指定案件类型数据列表
     */
    fun selectCaseListByCaseType(caseType: Int, pageNo: Int, pageSize: Int) {
        if (!checkNetWork()) {
            return
        }

        // 显示进度框
//        mView.showLoading()

        caseCenterService.selectCaseListByCaseType(caseType,pageNo,pageSize)
            .execute(object : BaseObserver<ApiPageInfo<CaseInfoEntity>>(mView) {
                override fun onNext(t: ApiPageInfo<CaseInfoEntity>) {
                    mView.onGetCaseInfoListSuccess(t)
                }
            }, lifecycleProvider)
    }

    /**
     * 保存批示信息
     * @author YangWei
     * @date 2019/5/5
     * @param authMsgEntity {@link AuthMsgEntity}
     * @return 成功/失败
     */
    fun saveAuthMsg(authMsgEntity: AuthMsgEntity) {
        if (!checkNetWork()) {
            return
        }

        if (authMsgEntity.userDeptInfoVoList!!.isEmpty()){
            mView.onError("请选择发送单位")
            return
        }

        // 显示进度框
        mView.showLoading()

        caseCenterService.saveAuthMsg(authMsgEntity)
            .execute(object : BaseObserver<Boolean>(mView) {
                override fun onNext(t: Boolean) {
                    mView.onGetSaveAuthMsgSuccess(t)
                }
            }, lifecycleProvider)
    }


    /**
     * 获取批示信息详情（批示内容及批示接收单位-人员信息）
     * @author YangWei
     * @date 2019/5/5
     * @param caseId    案件id
     * @param userId    当前操作人id
     * @return AuthMsgEntityVo {@link AuthMsgEntityVo}
     */
    fun getCaseAuthInfo(caseId: Long, userId: Long) {
        if (!checkNetWork()) {
            return
        }

        // 显示进度框
        mView.showLoading()

        caseCenterService.getCaseAuthInfo(caseId,userId)
            .execute(object : BaseObserver<AuthMsgEntityVo>(mView) {
                override fun onNext(t: AuthMsgEntityVo) {
                    mView.onGetCaseAuthInfoSuccess(t)
                }
            }, lifecycleProvider)
    }

    /**
     * 获取指定案件详情信息
     * @author YangWei
     * @date 2019/4/8
     * @param caseId    案件id
     * @return 指定案件详情信息
     */
//    fun getCaseInfoById(caseId:Long) {
//        if (!checkNetWork()) {
//            return
//        }
//
//        // 显示进度框
////        mView.showLoading()
//
//        caseCenterService.getCaseInfoById(caseId)
//            .execute(object : BaseObserver<CaseDetailInfoEntity>(mView) {
//                override fun onNext(t: CaseDetailInfoEntity) {
//                    mView.onGetCaseInfoSuccess(t)
//                }
//            }, lifecycleProvider)
//
//
//    }
}